#
# @version 0.1.2 (2010)
# @author Paolo Margara <paolo.margara@gmail.com>
# 
# Copyright 2010 Paolo Margara
#
# This file is part of Engine_cudamrg.
#
# Engine_cudamrg is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License or
# any later version.
# 
# Engine_cudamrg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Engine_cudamrg.  If not, see <http://www.gnu.org/licenses/>.
#

CC = @CC@
NVCC = @NVCC@

VERSION = @VERSION@

LDFLAGS= @LDFLAGS@
NVLDFLAGS= @NVLDFLAGS@

CPPFLAGS= @CPPFLAGS@
NVCPPFLAGS= @NVCPPFLAGS@

CFLAGS= @CFLAGS@

NVCFLAGS_LIBS = @NVCFLAGS@ --compiler-options '@CFLAGS@'
NVCFLAGS_TEST = @NVCFLAGS@ --compiler-options '@CFLAGS_TEST@'

LIBS = @LIBS@

LIBNAME = libcudamrg.so
TESTNAME= teststate

LIBSRC = e_cuda.c aes_cuda.cu
TESTSRC= teststate.c aes_cuda.cu

SOURCES= aes_cuda.cu e_cuda.c teststate.c
HEADERS= aes_cuda.h
OTHERFILES= configure COPYING openssl.cnf.example README CHANGES configure.in Makefile.in
OTHER_DIRS= openssl-patch test-enc test-speed test-file
OTHER_DIRS_CONTENT= openssl-patch/openssl-0.9.8.k-apps_speed.c.patch test-enc/aes-ecb-decrypt.plt test-enc/test-enc-plot.sh test-speed/aes-ecb-decrypt.plt \
	openssl-patch/openssl-0.9.8.k-crypto_evp_bio_enc.c.patch test-enc/aes-ecb-encrypt.plt test-file/test-file.sh test-speed/aes-ecb-encrypt.plt test-enc/aes-cbc-decrypt.plt \
	test-enc/test-enc-cpu.sh test-speed/aes-cbc-decrypt.plt test-enc/aes-cbc-encrypt.plt test-enc/test-enc-gpu.sh test-speed/aes-cbc-encrypt.plt test-speed/test-speed.sh          
ALLFILES=$(SOURCES) $(HEADERS) $(OTHERFILES) $(OTHER_DIRS)
distdir= @DISTDIR@
tarname= @TARNAME@

LIBOBJ = e_cuda.o aes_cuda.o
TESTOBJ= aes_cuda.o teststate.o

all:	lib test

test: $(TESTSRC)
	$(NVCC) $(NVCPPFLAGS) $(NVCFLAGS_TEST) $(NVLDFLAGS) $(LIBS) -o $(TESTNAME) $(TESTSRC)

lib:	$(LIBOBJ)
	$(CC) -shared -Wl,-soname,$(LIBNAME) $(CFLAGS_LIBS) $(CPPFLAGS) $(LDFLAGS) $(LIBS) -o $(LIBNAME) $(LIBOBJ)

aes_cuda.o: aes_cuda.cu
	$(NVCC) $(NVCPPFLAGS) $(NVCFLAGS_LIBS) -c -o $@ aes_cuda.cu 

install: lib
	mkdir -p @prefix@/@ENGINEDIR@
	cp $(LIBNAME) @prefix@/@ENGINEDIR@
	chmod 644 @prefix@/@ENGINEDIR@/$(LIBNAME)

uninstall:
	-rm -f @prefix@/@ENGINEDIR@/$(LIBNAME)
	

clean:
	rm -f *.o *.obj lib tags core .pure *.out .nfs* *.old *.bak fluff *.linkinfo *.so *.a teststate

distclean: clean FORCE
	rm -f config.* Makefile

dist: $(tarname)

$(tarname): $(distdir)
	tar cvzf $(tarname) $(distdir)
	rm -rf $(distdir)

$(distdir): $(ALLFILES) FORCE
	mkdir -p $(distdir)
	cp $(SOURCES) $(HEADERS) $(OTHERFILES) $(distdir)
	for i in $(OTHER_DIRS); do mkdir -p $(distdir)/$$i; done
	for i in $(OTHER_DIRS_CONTENT); do cp $$i $(distdir)/$$i; done

FORCE:
	-rm -rf $(distdir)
	-rm -f $(tarname)

.PHONY: all clean distclean dist FORCE install uninstall
